package o;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.BaseListFragment;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.lang.ref.WeakReference;
import java.util.List;

public class cha extends SomeFragmentStateAdapter {
    private int ʻ = -1;
    private WeakReference<BaseListFragment> ˊ;
    private List<dgp> ˎ;
    private chu ˏ;
    private WeakReference<Activity> ॱ;

    public cha(Activity activity, FragmentManager juVar, List<dgp> list) {
        super(juVar);
        this.ॱ = new WeakReference(activity);
        this.ˎ = list;
        Logger.ˎ("TabListPagerAdapter", "TabListPagerAdapter, tabItemList.size: " + list.size());
    }

    protected List<dgp> ॱ() {
        return this.ˎ;
    }

    public int getCount() {
        if (this.ˎ != null) {
            return this.ˎ.size();
        }
        return 0;
    }

    public int getItemPosition(Object obj) {
        super.getItemPosition(obj);
        return -2;
    }

    public CharSequence getPageTitle(int i) {
        if (CollectCheck.isEmpty(this.ˎ)) {
            return null;
        }
        if (isRTL()) {
            i = (getCount() - i) - 1;
        }
        dgp o_dgp = (dgp) this.ˎ.get(i);
        if (o_dgp == null || TextUtils.isEmpty(o_dgp.ˊ())) {
            return null;
        }
        return o_dgp.ˊ();
    }

    public Fragment getItem(int i) {
        Fragment fragment;
        boolean z = true;
        if (CollectCheck.isEmpty(this.ˎ)) {
            Logger.e("TabListPagerAdapter", "getItem, tabItemList: " + (this.ˎ == null ? HwAccountConstants.NULL : Integer.valueOf(this.ˎ.size())));
            fragment = null;
        } else {
            Fragment ˋ;
            dgp o_dgp = (dgp) this.ˎ.get(i);
            if (o_dgp != null) {
                chx o_chx = new chx();
                o_chx.ˋ(true);
                o_chx.ˊ(o_dgp.ˏ());
                o_chx.ˋ(o_dgp.ॱ());
                o_chx.ˎ(o_dgp.ʽ());
                o_chx.ˋ(o_dgp.ˊ());
                if (o_dgp.ॱˊ()) {
                    z = false;
                }
                o_chx.ˊ(z);
                o_chx.ˏ(o_dgp.ˋ());
                o_chx.ॱ(false);
                o_chx.ॱ(o_dgp.ˊॱ());
                o_chx.ˏ(o_dgp.ʼ());
                o_chx.ˏ(o_dgp.ʻ());
                o_chx.ˏ(false);
                o_chx.ॱ(o_dgp.ॱॱ());
                o_chx.ˎ(o_dgp.ᐝ());
                o_chx.ˋ(o_dgp.ॱˊ() ? chb.SECONDARY_MULTI_TAB : chb.SECONDARY_LIST_TAB);
                ˋ = ˋ(o_chx);
                if (ˋ == null) {
                    cjm ˋ2 = cju.ˋ(o_dgp.ˏ(), o_chx);
                    if (ˋ2 != null) {
                        ˋ = cjk.ˎ().ˊ(ˋ2);
                    } else {
                        Logger.e("TabListPagerAdapter", "getItem, offer == null, position: " + i);
                    }
                }
                if (ˋ != null) {
                    if ((ˋ instanceof cid) && this.ʻ != i) {
                        ((cid) ˋ).ॱᐝ(4);
                    }
                    if (this.ʻ == i) {
                        this.ʻ = -1;
                    }
                }
            } else {
                Logger.e("TabListPagerAdapter", "getItem, tabItem == null, position: " + i);
                ˋ = null;
            }
            fragment = ˋ;
        }
        if (fragment != null) {
            return fragment;
        }
        fragment = new Fragment();
        Logger.e("TabListPagerAdapter", "getItem, ft == null, position: " + i);
        return fragment;
    }

    protected Fragment ˋ(chx o_chx) {
        return chk.ˊ(o_chx.ˊॱ(), o_chx);
    }

    public void setPrimaryItem(ViewGroup viewGroup, int i, Object obj) {
        if (isRTL()) {
            i = (getCount() - i) - 1;
        }
        Fragment fragment = (Fragment) obj;
        if (fragment != this.mCurrentPrimaryItem) {
            if (fragment instanceof ciy) {
                ((ciy) fragment).ˋ(i);
            }
            ˊ(fragment);
            if (this.mCurrentPrimaryItem instanceof ciy) {
                ((ciy) this.mCurrentPrimaryItem).ʽˊ();
            }
            if (this.mCurrentPrimaryItem instanceof cid) {
                ((cid) this.mCurrentPrimaryItem).ॱᐝ(4);
            }
        }
        super.setPrimaryItem(viewGroup, i, obj);
    }

    public void ˎ(Bundle bundle) {
        if (bundle != null) {
            ˋ(bundle);
        } else {
            Logger.e("TabListPagerAdapter", "refreshTabPage, bundle == null");
        }
    }

    private void ˋ(Bundle bundle) {
        for (int i = 0; i < this.mFragments.size(); i++) {
            Fragment fragment = (Fragment) this.mFragments.get(i);
            if (fragment instanceof cic) {
                ((cic) fragment).ˎ(bundle);
            } else if (fragment != null || this.ˏ == null) {
                Logger.e("TabListPagerAdapter", "notifyChanged, fragment = " + fragment + ", iTabPageListener = " + this.ˏ);
            } else {
                dgp o_dgp = (dgp) this.ˎ.get(i);
                if (o_dgp != null) {
                    this.ˏ.ॱ(o_dgp, bundle);
                }
            }
        }
    }

    public Fragment ॱ(int i) {
        if (this.mFragments == null || this.mFragments.size() <= i || i < 0) {
            return null;
        }
        return (Fragment) this.mFragments.get(i);
    }

    public void ˏ(chu o_chu) {
        this.ˏ = o_chu;
    }

    public void ˊ() {
        this.ॱ = null;
        this.ˊ = null;
    }

    public void finishUpdate(ViewGroup viewGroup) {
        if (this.ॱ == null) {
            Logger.e("TabListPagerAdapter", "finishUpdate, activity = null");
            return;
        }
        try {
            if (ActivityUtil.isAcitivtyNotValid((Activity) this.ॱ.get())) {
                Logger.e("TabListPagerAdapter", "finishUpdate, activity destroyed");
            } else {
                super.finishUpdate(viewGroup);
            }
        } catch (Throwable e) {
            Logger.ˋ("TabListPagerAdapter", "finishUpdate, exception!", e);
        }
    }

    public Fragment ʼ() {
        return this.mCurrentPrimaryItem;
    }

    public void ˏ(BaseListFragment baseListFragment) {
        this.ˊ = new WeakReference(baseListFragment);
    }

    private void ˊ(Fragment fragment) {
        int i;
        if (this.ˊ != null) {
            BaseListFragment baseListFragment = (BaseListFragment) this.ˊ.get();
            if (!(baseListFragment == null || baseListFragment.ʽʼ() == 0)) {
                i = 0;
                if (i != 0 && (fragment instanceof cid) && ((cid) fragment).ʽʼ() != 0) {
                    ((cid) fragment).ॱᐝ(0);
                    return;
                }
                return;
            }
        }
        i = 1;
        if (i != 0) {
        }
    }

    public void ˋ(int i) {
        this.ʻ = i;
    }
}
